package cn.xyh.util;


import cn.xyh.constant.MapCache;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertyUtil {
    private static String filename_conf = "conf.properties";
    private static Properties config_conf = null;

    private PropertyUtil() {
        config_conf = new Properties();
        String path = this.getClass().getClassLoader().getResource("").getPath();
        try {
            // path = URLDecoder.decode(path, "utf-8");
            config_conf.load(new FileInputStream(path + filename_conf));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private static class LazyLoading {
        private static final PropertyUtil instance = new PropertyUtil();
    }

    public static PropertyUtil getInstance() {
        return LazyLoading.instance;
    }


    public static String getConfValue(String confKey) {
        String value = null;
        if (MapCache.datas.containsKey(confKey)) {
            value = MapCache.datas.get(confKey).toString();
        }
        if (StringUtils.isBlank(value)) {
            getInstance();
            value = config_conf.getProperty(confKey);
        }
        return value;
    }


}
